$(document).ready(function(){
    $(".nav .item-title").click(function(){
        $(this).addClass("active").parent().siblings().find(".item-title").removeClass("active");
        var type = $(this).attr("data-type");
        changeTab(type);
    });
});

function changeTab(tab) {
    renderTable({}, tab);
    request(tab)
}
function renderTable(data, type) {
    var tHead = {
        a: ['时间', "数量"],
        b: ['时间', '数量'],
        // c: ['时间', '直推奖励积分'],
    }[type];

    var table = $("#table");
    var html = '';
    // 渲染表头部份
    html += '<thead><tr>'
    for (var i = 0; i < tHead.length; i++) {
        html += '<th style="width: 40%;">' + tHead[i] + '</th>';
    }
    html += '</tr></thead>';
    table.html(html);

    html += '<tbody>';
    if (type == 'a') {
        for (var i = 0; i < data.length; i++) {
            html += '<tr><td>' + data[i].date_time +'</td><td>' + data[i].ice_tree +'</td></tr>';
        }
    }
    if (type == 'b') {
        for (var i = 0; i < data.length; i++) {
            html += '<tr><td>' + data[i].date_time +'</td><td>' + data[i].ice_tree +'</td></tr>';
        }
    }

    html += '</tbody></table>';
    table.html(html);
   
}
function request(type) {
    loading(1)
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Info/icetreelog/" ,//url
        data: {type: type},
        success: function (result) {
            loading(0)
            renderTable(result.data, type);
        },
        error : function() {
            loading(0)
            notify("异常！");
        }
    });
}